<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>refs使用</title>
</head>
<body>
  <!-- 准备容器 -->
  <div id="test"></div>
  <!-- 按照顺序引入 -->
  <script type="text/javascript" src="../../js/react.development.js"></script>
  <script type="text/javascript" src="../../js/react-dom.development.js"></script>
  <script type="text/javascript" src="../../js/babel.min.js"></script>
  <script type="text/babel" >
    class Demo extends React.Component {
        render(){
            // 组件内的标签可以定义ref属性来标识自己
            // 不推荐使用字符串形式的ref 效率不高 refs是使用React.createRef()创建的
            return (
                <div>
                    <input ref="input1" type="text" placeholder="点击右侧按钮显示数据"/>&nbsp;&nbsp;
                    <button ref="button1" onClick={this.showData1}>点击显示左侧数据</button>&nbsp;&nbsp;
                    <input ref="input2" type="text" onBlur={this.showData2} placeholder="失去焦点显示数据" />    
                </div>
            )
        }
        showData1=()=>{
            console.log(this);
            alert(this.refs.input1.value)
            // const input1 = document.getElementById('input1')
            // alert(input1.value)
        }
        showData2=()=>{

            alert(this.refs.input2.value)
            // const input1 = document.getElementById('input1')
            // alert(input1.value)
        }    
    }
    ReactDOM.render(<Demo/>,document.getElementById('test'))
  </script>
</body>
</html>